﻿# coding: utf-8

import os
import wx
import wx.lib.filebrowsebutton as filebrowse

class wxDialogWaterCreate(wx.Dialog):
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent, title = TD.TERRAIN_CREATE)

        sizerWidth = self.__CreateUIWaterWidth()
        sizerLength = self.__CreateUIWaterLength()
        sizerGridSize = self.__CreateUIGridSize()
        sizerShaderFile = self.__CreateUIShaderFile()
        sizerBumpTexture = self.__CreateUIBumpTexture()
        sizerOkCancel = self.__CreateUIOkCancel()
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(sizerWidth, 0, wx.LEFT|wx.RIGHT|wx.TOP|wx.EXPAND, border = 10)
        sizer.Add(sizerLength, 0, wx.LEFT|wx.RIGHT|wx.EXPAND, border = 10)
        sizer.Add(sizerGridSize, 0, wx.LEFT|wx.RIGHT|wx.EXPAND, border = 10)
        sizer.Add(sizerShaderFile, 0, wx.LEFT|wx.RIGHT|wx.EXPAND, border = 10)
        sizer.Add(sizerBumpTexture, 0, wx.LEFT|wx.RIGHT|wx.EXPAND, border = 10)
        sizer.Add(sizerOkCancel, 0, wx.CENTER, border = 15)
        self.SetSizer(sizer)
        self.Fit()

    def __CreateUIWaterWidth(self):
        staticWaterWidth = wx.StaticText(self, wx.NewId(), TD.WATER_WIDTH)
        self._editWaterWidth = wx.TextCtrl(self, wx.NewId())
        sizerWaterWidth = wx.BoxSizer(wx.HORIZONTAL)
        sizerWaterWidth.Add(staticWaterWidth, 0, wx.CENTER, border = 5)
        sizerWaterWidth.Add(self._editWaterWidth, 1, wx.ALL|wx.EXPAND, border = 5)
        return sizerWaterWidth
        
    def __CreateUIWaterLength(self):
        staticWaterLength = wx.StaticText(self, wx.NewId(), TD.WATER_LENGTH)
        self._editWaterLength = wx.TextCtrl(self, wx.NewId())
        sizerWaterLength = wx.BoxSizer(wx.HORIZONTAL)
        sizerWaterLength.Add(staticWaterLength, 0, wx.CENTER, border = 5)
        sizerWaterLength.Add(self._editWaterLength, 1, wx.ALL|wx.EXPAND, border = 5)
        return sizerWaterLength
        
    def __CreateUIGridSize(self):
        staticWaterGridSize = wx.StaticText(self, wx.NewId(), TD.WATER_GRID_SIZE)
        self._editGridSize = wx.TextCtrl(self, wx.NewId())
        sizerGridSize = wx.BoxSizer(wx.HORIZONTAL)
        sizerGridSize.Add(staticWaterGridSize, 0, wx.CENTER, border = 5)
        sizerGridSize.Add(self._editGridSize, 1, wx.ALL|wx.EXPAND, border = 5)
        return sizerGridSize
        
    def __CreateUIShaderFile(self):
        path = os.path.join(GLOBAL_SETTING._workDir, GLOBAL_SETTING._waterShaderFile)
        self._fbbShaderFile = filebrowse.FileBrowseButton(
            self, -1, labelText= TD.WATER_SHADER_FILE,
            size = (500, -1),
            buttonText= TD.BUTTON_BROWSE, 
            changeCallback = self.__OnShaderFileChanged,
            startDirectory = path,
            fileMask = '*.fx')
        
        if GLOBAL_SETTING._waterShaderFile:
            self._fbbShaderFile.SetValue(path)
            
        sizerShaderFile = wx.BoxSizer(wx.HORIZONTAL)
        sizerShaderFile.Add(self._fbbShaderFile, 1, wx.ALL|wx.EXPAND, border = 5)
        return sizerShaderFile
    
    def __CreateUIBumpTexture(self):
        path = os.path.join(GLOBAL_SETTING._workDir, GLOBAL_SETTING._waterBumpTextureFile)
        self._fbbBumpTextureFile = filebrowse.FileBrowseButton(
            self, -1, labelText = TD.WATER_BUMP_TEXTURE_FILE,
            buttonText = TD.BUTTON_BROWSE,
            changeCallback = self.__OnBumpTextureFileChanged,
            startDirectory = path,
            fileMask = 'DDS Files(*.dds)|*.dds|All Files(*.*)|*.*')
        
        if GLOBAL_SETTING._waterBumpTextureFile:
            self._fbbBumpTextureFile.SetValue(path)
        
        sizerBumpTexture = wx.BoxSizer(wx.HORIZONTAL)
        sizerBumpTexture.Add(self._fbbBumpTextureFile, 1, wx.ALL|wx.EXPAND, border = 5)
        return sizerBumpTexture
                        
    def __CreateUIOkCancel(self):
        bnWaterCreateOk = wx.Button(self, wx.ID_OK, TD.BUTTON_OK)
        bnWaterCreateCancel = wx.Button(self, wx.ID_CANCEL, TD.BUTTON_CANCEL)
        sizerOkCancel = wx.BoxSizer(wx.HORIZONTAL)
        sizerOkCancel.Add(bnWaterCreateOk, 0, wx.ALL, border = 15)
        sizerOkCancel.Add(bnWaterCreateCancel, 0, wx.ALL, border = 15)
        return sizerOkCancel
        
    def __OnShaderFileChanged(self, e):
        v = self._fbbShaderFile.GetValue()
        GLOBAL_SETTING._waterShaderFile = REMOVE_ROOT_PATH(v)
        
    def __OnBumpTextureFileChanged(self, e):
        v = self._fbbBumpTextureFile.GetValue()
        GLOBAL_SETTING._waterBumpTextureFile = REMOVE_ROOT_PATH(v)
        
    def GetWidth(self):
        return int(self._editWaterWidth.GetValue())
        
    def GetLength(self):
        return int(self._editWaterLength.GetValue())
    
    def GetGridSize(self):
        return float(self._editGridSize.GetValue())
        
    def GetShaderFile(self):
        return REMOVE_ROOT_PATH(self._fbbShaderFile.GetValue())
    
    def GetBumpTextureFile(self):
        return REMOVE_ROOT_PATH(self._fbbBumpTextureFile.GetValue())
        
        
        
        
        
        
        
        
        
        
        
        
        
    